﻿@inject IOptionsMonitor<WebsiteOptions> WebsiteOption

<div>
    <p><h5>Word</h5></p>
    <FileViewer Filename="@WordSampleFile" Height="300px" StyleString="padding: var(--bs-card-cap-padding-y) var(--bs-card-cap-padding-x);border: var(--bs-card-border-width) solid var(--bs-card-border-color);" />
    <br />
    <p><h5>Excel</h5></p>
    <FileViewer Filename="@ExcelSampleFile" Height="300px" StyleString="padding: var(--bs-card-cap-padding-y) var(--bs-card-cap-padding-x);border: var(--bs-card-border-width) solid var(--bs-card-border-color);" />
</div>

@code {
    [NotNull]
    private string? WordSampleFile { get; set; }

    [NotNull]
    private string? ExcelSampleFile { get; set; }

    /// <summary>
    /// OnInitialized
    /// </summary>
    protected override void OnInitialized()
    {
        WordSampleFile = CombineFilename("sample.docx");
        ExcelSampleFile = CombineFilename("sample.xlsx");
    }

    /// <summary>
    /// CombineFilename
    /// </summary>
    /// <param name="filename"></param>
    /// <returns></returns>
    private string CombineFilename(string filename)
    {
#if DEBUG
        filename = Path.Combine(WebsiteOption.CurrentValue.WebRootPath, "samples", filename);
#else
        filename = Path.Combine(WebsiteOption.CurrentValue.ContentRootPath, "wwwroot", "samples", filename);
#endif
        return filename;
    }
}
